package com.amphiprion.prototype.util;

import android.graphics.PointF;

import com.amphiprion.prototype.ScreenProperty;

public class DrawUtil {

	public static double getDistance(PointF p1, PointF p2) {
		return Math.sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y));
	}

	/**
	 * return angle between -180 and 180
	 * 
	 * @param p
	 * @param center
	 * @return
	 */
	public static float getAngle(PointF p, PointF center) {
		return (float) (Math.atan2(p.y - center.y, p.x - center.x) * 180 / Math.PI);
	}

	public static float getDifferenceAngle(float angle1, float angle2) {
		float dif = (angle2 - angle1) % 360; // in range
		if (angle1 > angle2) {
			dif += 360;
		}
		if (dif >= 180) {
			dif = -(dif - 360);
		}
		return dif;
	}

	public static float convertX(float x, float y, ScreenProperty screenProperty) {
		float newX = x;
		if (screenProperty.screenRotation == 90) {
			newX = y;
		}
		newX /= screenProperty.screenScale;
		newX += screenProperty.screenOffsetX;
		return newX;
	}

	public static float convertY(float x, float y, ScreenProperty screenProperty) {
		float newY = y;
		if (screenProperty.screenRotation == 90) {
			newY = screenProperty.realWidth - x;
		}
		newY /= screenProperty.screenScale;
		newY += screenProperty.screenOffsetY;
		return newY;
	}
}
